package com.dlc.shop.api.controller;


import com.dlc.shop.bean.dto.FlowLogDto;
import com.dlc.shop.bean.model.FlowLog;
import com.dlc.shop.common.response.ServerResponseEntity;
import com.dlc.shop.common.util.BeanUtil;
import com.dlc.shop.security.api.util.SecurityUtils;
import com.dlc.shop.service.FlowLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 用户流量记录
 *
 * @author YXF
 * @date 2020-07-13 13:18:33
 */
@RestController
@RequestMapping("/p/flowAnalysisLog")
@Tag(name = "用户流量记录接口")
@AllArgsConstructor
public class FlowLogLoginController {

    private final FlowLogService flowLogService;


    @PostMapping
    @Operation(summary = "新增用户流量记录")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid FlowLogDto flowLogDto) {
        FlowLog flowLog = BeanUtil.map(flowLogDto, FlowLog.class);
        flowLog.setUserId(SecurityUtils.getUser().getUserId());
        flowLogService.saveUserFlowLog(flowLog);
        return ServerResponseEntity.success();
    }
}
